package com.hunau.cxb.dao.impl;

import com.hunau.cxb.dao.BookStockDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @author hb
 * @create 2020-03-22 10:38
 */
@Repository
public class BookStockDaoImpl implements BookStockDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

       @Override
    public int queryByIsbn(String isbn) {
        return jdbcTemplate.queryForObject("select stock from t_bookstock where isbn=?",new Object[]{isbn},Integer.class);
    }

    @Override
    public void updateStock(String isbn, int nums) {
      jdbcTemplate.update("update t_bookstock set stock=stock-? where isbn=?",nums,isbn);
    }
}
